#!/usr/bin/make -f

#  originally from https://raw.githubusercontent.com/junland/hello-deb/master/debian/rules
export DH_OPTIONS

##
# From git-lfs/git-lfs repo:
# Looks like dh_golang doesn't set diffrent archs, so you have to do them semi-manually.
##

## This if-structure is decided on what is passed by the -a flag by dpkg-buildpackage command.
ifeq ($(DEB_HOST_ARCH), i386)
	export GOARCH := 386
else ifeq ($(DEB_HOST_ARCH), amd64)
	export GOARCH := amd64
else ifeq ($(DEB_HOST_ARCH), armhf)
	export GOARCH := arm
  	# May need to set GOARM as well if your going to target ARM. But for now this works.
else ifeq ($(DEB_HOST_ARCH), arm64)
	export GOARCH := arm64
endif

# Or add your arch that your targeting, these are just examples.

# Directory where compiled binary is placed + debian setup files. 
# Note: If your doing building thru git, you may want to add obj-* to .gitignore
BUILD_DIR := obj-$(DEB_HOST_GNU_TYPE)

REPO    := goarista
WHOAMI  := themusicgod1
NOTABUG := notabug
# Required: Put the url (without http://) of your git repo.
export DH_GOPKG := notabug.org/$(WHOAMI)/$(REPO)

# Required: Put the name of your git repo below. 
GIT_REPO_NAME := $(NOTABUG)-$(WHOAMI)-$(REPO)

export PATH := $(CURDIR)/$(BUILD_DIR)/bin:$(PATH)

##
# From git-lfs/git-lfs repo:
# by-default, dh_golang only copies *.go and other source - this upsets a bunch of vendor test routines
##
export DH_GOLANG_INSTALL_ALL := 1

%:
	dh $@ --buildsystem=golang --with=golang

override_dh_clean:
	rm -f debian/debhelper.log
	dh_clean

override_dh_auto_build:
	dh_auto_build -- -ldflags "-s -w"
	##
	# From git-lfs/git-lfs repo:
	# dh_golang doesn't do anything here in deb 8, and it's needed in both
	##
	if [ "$(DEB_HOST_GNU_TYPE)" != "$(DEB_BUILD_GNU_TYPE)" ]; then\
		cp -rf $(BUILD_DIR)/bin/*/* $(BUILD_DIR)/bin/; \
		cp -rf $(BUILD_DIR)/pkg/*/* $(BUILD_DIR)/pkg/; \
	fi
	
override_dh_strip:
	##
	# From git-lfs/git-lfs repo:
	# strip disabled as golang upstream doesn't support it and it makes go crash.
	# See https://launchpad.net/bugs/1200255.
	##

#override_dh_golang:
	##
	# From git-lfs/git-lfs repo:
	# The dh_golang is used to add the Built-using field to the deb.  This is only for reference.
	# As of https://anonscm.debian.org/cgit/collab-maint/dh-golang.git/commit/script/dh_golang?id=7c3fbec6ea92294477fa8910264fe9bd823f21c3
	# dh_golang errors out because the go compiler used was not installed via a package.  Therefore the step is skipped
	##

#override_dh_auto_install:
	# golang-notabug-themusicgod1-panicparse-dev
	# This is making a "fakeroot" so that when the deb is installed the binary will be placed in /usr/bin.
#	mkdir -p debian/golang-$(GIT_REPO_NAME)-dev/usr/bin
#	mkdir -p debian/golang-$(GIT_REPO_NAME)-dev/usr/share/gocode/src/notabug.org/$(WHOAMI)/$(REPO)

	# This is copying the binary and placing it in the fake root path.
#	cp $(BUILD_DIR)/bin/panicparse debian/golang-$(GIT_REPO_NAME)-dev/usr/bin/
#	cp $(BUILD_DIR)/bin/panic debian/golang-$(GIT_REPO_NAME)-dev/usr/bin/
#	cp $(BUILD_DIR)/bin/pp debian/golang-$(GIT_REPO_NAME)-dev/usr/bin/
#	cp -r $(BUILD_DIR)/src/notabug.org/themusicgod1/panicparse/stack debian/golang-$(GIT_REPO_NAME)-dev/usr/share/gocode/src/notabug.org/$(WHOAMI)/$(REPO)


# #!/usr/bin/make -f

#export DH_OPTIONS 
#%:
#	dh $@ --buildsystem=golang --with=golang
